﻿/* ######################################## *\
 * ### Copyright (C) 2009 AJ Ravindiran ### *
\* ######################################## */
using System;
using System.IO;
using System.Collections.Generic;

namespace AJRavindiran.Jolt.RuneScape.Models.World
{
    /// <summary>
    /// Represents a map data loader.
    /// </summary>
    public class MapDataLoader
    {
        /// <summary>
        /// Load map data from the regions.dat binary file.
        /// </summary>
        public static void Load(Dictionary<int, int[]> map)
        {
            try
            {
                BinaryReader reader = new BinaryReader(File.OpenRead(@".\bin\data\mapdata\regions.dat"));

                while (reader.PeekChar() >= 0)
                {
                    int mapId = reader.ReadInt32();
                    int[] mapData = new int[4];

                    for (int j = 0; j < 4; j++)
                        mapData[j] = reader.ReadInt32();

                    map.Add(mapId, mapData);
                }
                reader.Close();
                reader.Dispose();
            }
            catch (Exception ex)
            {
                Jolt.GetLog().WriteException(ex);
            }
        }
    }
}
